package com.tongzhan.utils;


import java.io.Serializable;

/**
 * @author htmic
 * @create 2019年11月26日10:27:05
 * @description
 */
public class ThreadLocalUtil {

    /**
     * 用户信息
     */
    private static final ThreadLocal<AdminThreadLocal> threadLocal = new ThreadLocal<>();

    /**
     * 清理线程
     */
    public static void clearThreadLocal() {
        threadLocal.remove();
    }

    /**
     * 设置常用信息
     *
     * @param userThreadLocal
     */
    public static void putCurrentRequestBasicVO(AdminThreadLocal userThreadLocal) {
        if (userThreadLocal == null) {
            return;
        }
        ThreadLocalUtil.threadLocal.set(userThreadLocal);
    }

    /**
     * 获取常用信息
     *
     * @param
     */
    public static AdminThreadLocal getThreadLocal() {
        AdminThreadLocal userThreadLocal = threadLocal.get();
        return userThreadLocal;
    }

    public static String STREET_CODE = "z1";
    public static String VILLAGE_CODE = "c1";

    public static class AdminThreadLocal implements Serializable {
        private static final long serialVersionUID = 1L;
        /**
         * 用户token
         */
        private String token;
        /**
         * 用户ID
         */
        private String userId;
        /**
         * 用户昵称
         */
        private String userName;

        /**
         * 权限code z1：镇街道，c1：村社区
         */
        private String dutiesCode;

        /**
         * 镇/街道
         */
        private String streetCode;

        /**
         * 村/社区
         */
        private String villageCode;

        public String getToken() {
            return token;
        }

        public void setToken(String token) {
            this.token = token;
        }

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getStreetCode() {
            return streetCode;
        }

        public void setStreetCode(String streetCode) {
            this.streetCode = streetCode;
        }

        public String getVillageCode() {
            return villageCode;
        }

        public void setVillageCode(String villageCode) {
            this.villageCode = villageCode;
        }

        public String getDutiesCode() {
            return dutiesCode;
        }

        public void setDutiesCode(String dutiesCode) {
            this.dutiesCode = dutiesCode;
        }
    }

}

